
Partial Class PasswordChange
    Inherits System.Web.UI.Page

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        Response.Cache.SetCacheability(HttpCacheability.NoCache)
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim uname As String
        Dim a As New Globo
        If Session("type") = "" Then
            Response.Redirect("Error.aspx")
            Exit Sub
        Else
            lnkProfName.Text = "Logged in as " & Session("prim") & " (" & Session("sec") & ")"
            uname = Session("prim")

            'If Session("type") = "admin" Then
            '    a.executesql("select adminid from admin where adminid='" & uname & "'", False)
            'ElseIf Session("type") = "user" Then
            '    a.executesql("select uid from users where uid='" & uname & "'", False)
            'ElseIf Session("type") = "buyer" Then
            '    a.executesql("select buyer_id from buyers where buyer_id='" & uname & "'", False)
            'End If
        End If

        'uname = "rhythmdivine"
        txtUname.Text = uname
    End Sub

    Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
        If txtPswdOld.Text = "" Then
            lblErr.Text = "Enter Old Password"
            lblErr.Visible = True
            Exit Sub
        End If

        If txtPswdNew.Text = "" Then
            lblErr.Text = "Enter New Password"
            lblErr.Visible = True
            Exit Sub
        End If

        If txtRePswd.Text = "" Then
            lblErr.Text = "Retype New Password"
            lblErr.Visible = True
            Exit Sub
        End If



        Dim uname, pswd, npswd As String
        uname = txtUname.Text
        pswd = txtPswdOld.Text

        Dim a As New Globo
        If Session("type") = "admin" Then
            a.executesql("select * from admin where adminid='" & uname & "' and adminpass='" & pswd & "'", False)
        ElseIf Session("type") = "user" Then
            a.executesql("select * from users where uid='" & uname & "' and pass='" & pswd & "'", False)
        ElseIf Session("type") = "buyer" Then
            a.executesql("select * from buyers where buyer_id='" & uname & "' and bpassword='" & pswd & "'", False)
        End If

        If a.dr.Read = False Then
            lblErr.Text = "Password incorrect."
            lblErr.Visible = True
            Exit Sub
        End If

        If txtPswdNew.Text <> txtRePswd.Text Then
            lblErr.Text = "Password Mismatch"
            lblErr.Visible = True
            Exit Sub
        End If



        Dim b As New Globo
        npswd = txtPswdNew.Text
        If Session("type") = "admin" Then
            b.executesql("update admin set adminpass='" & npswd & "' where adminid='" & uname & "'", True)
            MsgBox("Your password has been changed successfully!", MsgBoxStyle.OkOnly, "Password change confirmation")
            Response.Redirect("AProfile.aspx")
        ElseIf Session("type") = "user" Then
            b.executesql("update users set pass='" & npswd & "' where uid='" & uname & "'", True)
            MsgBox("Your password has been changed successfully!", MsgBoxStyle.OkOnly, "Password change confirmation")
            Response.Redirect("UProfile.aspx")
        ElseIf Session("type") = "buyer" Then
            b.executesql("update buyers set bpassword='" & npswd & "' where buyer_id='" & uname & "'", True)
            MsgBox("Your password has been changed successfully!", MsgBoxStyle.OkOnly, "Password change confirmation")
            Response.Redirect("BProfile.aspx")
        End If
    End Sub

    '_________________________________________________________________________________________________________________________________
    '#################################################################################################################################
    Protected Sub lnkProfName_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkProfName.Click
        If Session("type") <> "" Then
            Dim str As String
            str = UCase(Left(Session("type"), 1))
            Response.Redirect("" & str & "Profile.aspx")
        End If
    End Sub

    'Protected Sub lnkQuery_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkQuery.Click
    '    Response.Redirect("Query.aspx")
    'End Sub

    Protected Sub lnkThemes_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkThemes.Click
        Response.Redirect("Themes.aspx")
    End Sub

    Protected Sub lnkSettings_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkSettings.Click
        Response.Redirect("Settings.aspx")
    End Sub

    Protected Sub lnkLogOut_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkLogOut.Click
        Server.Transfer("Loading.aspx")
    End Sub

    '_____________________________________________________________________________________________________________
    '*************************************************************************************************************
    Protected Sub lnkAboutUs_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkAboutUs.Click
        Response.Redirect("AboutUs.aspx")
    End Sub

    Protected Sub lnkTermCond_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkTermCond.Click
        Response.Redirect("TermsConditions.aspx")
    End Sub

    Protected Sub lnkContactUs_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkContactUs.Click
        Response.Redirect("ContactUs.aspx")
    End Sub

    Protected Sub lnkFAQs_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkFAQs.Click
        Response.Redirect("FAQs.aspx")
    End Sub

    Protected Sub lnkFeedback_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkFeedback.Click
        Response.Redirect("Feedback.aspx")
    End Sub
End Class